package com.tj.api.rest;

import com.fqgj.base.services.redis.RedisClient;
import com.fqgj.common.utils.HttpUtil;
import com.fqgj.common.utils.StringUtils;
import com.tj.api.annotations.SignIgnore;
import com.tj.api.task.MarketOddsChangeTask;
import com.tj.api.task.RollbackMarketOddsTask;
import com.tj.bo.account.server.dao.TestAccountDao;
import com.tj.bo.account.server.entity.TestAccountEntity;
import com.tj.bo.common.conf.api.ApiResponse;
import com.tj.bo.common.conf.constant.RedisKey;
import com.tj.bo.product.server.dao.TestProductDao;
import com.tj.bo.trade.server.dao.TestTradeDao;
import com.tj.bo.user.client.UserWanningListService;
import com.tj.template.application.trade.OrderApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: binary (mr.vencnet@gmail.com)
 * Date: 2020-06-02
 * Time: 17:18
 */
@RestController
@RequestMapping("/test/a92307a372634fcebeed06f6db3df92d")
public class TestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private TestTradeDao testTradeDao;

    @Autowired
    private TestProductDao testProductDao;

    @Autowired
    private TestAccountDao testAccountDaol;

    @Autowired
    private OrderApplication orderApplication;

    @Autowired
    private RedisClient redisClient;

    @Autowired
    private MarketOddsChangeTask marketOddsChangeTask;

    @Autowired
    private RollbackMarketOddsTask rollbackMarketOddsTask;

    @RequestMapping("/ok/db")
    @SignIgnore
    public String testDb() {
        TestAccountEntity testAccountEntity = testAccountDaol.selectByPrimaryKey(1L);
        return testAccountEntity.getAppName();
    }

    @RequestMapping("/ok/redis")
    @SignIgnore
    public String redis() {

        String key = "aa";
        redisClient.set(key, "19999");
        return redisClient.get(key);

    }

    @SignIgnore
    @RequestMapping("/changeMarketOdds")
    @ResponseBody
    public ApiResponse changeMarketOdds() {
        marketOddsChangeTask.changeMarketOdds();
        return new ApiResponse<>();
    }

    @SignIgnore
    @RequestMapping("/rollbackMarketOddsTask")
    @ResponseBody
    public ApiResponse rollbackMarketOddsTask() {
        rollbackMarketOddsTask.rollbackMarketOddsTask();
        return new ApiResponse<>();
    }

    @SignIgnore
    @RequestMapping("/changeUserOdds/{userCode}/{productCode}")
    @ResponseBody
    public ApiResponse func1(@PathVariable("userCode") String userCode, @PathVariable("productCode") String productCode) {
        redisClient.listLeftPush(RedisKey.BINARY_OPTION_ODDS_CALC_LIST, userCode + "," + productCode);
        return new ApiResponse<>();
    }


    @Autowired
    private UserWanningListService userWanningListService;


//    @SignIgnore
//    @RequestMapping("/test01")
//    @ResponseBody
//    public ApiResponse test01(@RequestBody JSONObject jsonObject) {
//        if (userWanningListService.isGrey(jsonObject.getString("userCode"))) {
//            //灰名单用户
//            MessageMQ messageMQ = new MessageMQ();
//            messageMQ.setMessageId(jsonObject.getString("tradeNo"));
//            messageMQ.setMessage(jsonObject.getString("tradeNo"));
//            messageMQ.setTopic(MQTopicEnum.BINARY_OPTION);
//            messageMQ.setTag(MQTagEnum.MANIPULATE);
//            messageMQ.setDelay(40L);
//            messageMQHandler.send(messageMQ);
//        }
//        return new ApiResponse<>();
//    }

    public static void main(String[] args) {
        String str = "20200811040123977351UC002970|C_ETH_USD";
        String[] strArr = str.split(",");
        for (String s : strArr) {
            if (StringUtils.isEmpty(s)) {
                continue;
            }
            String[] ss = s.split("\\|");
            String userCode = ss[0];
            String productCode = ss[1];

            String rest = HttpUtil.getPage("https://app-api.abctradeapp.com/test/a92307a372634fcebeed06f6db3df92d/changeUserOdds/" + userCode + "/" + productCode);
            System.out.println("----" + s + "----------" + rest);
        }
    }

}
